<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../../vue.js"></script>
  </head>
  <body>
    <div id="app">
      <button @click="changePerson">改变数据</button>
      <div>person--->{{person}}</div>
    </div>
    <script>
      Vue.config.productionTip = false;
      const vm = new Vue({
        el: "#app",
        data() {
          return {
            name: "余海海",
            age: 30,
          };
        },
        methods: {
          changePerson() {
            /* 
                    因为vue2 响应式原理的底层原理无法监听对象的删除和新增
                    vue2新增提供了两个方法，可以响应式的新增和删除对象的属性(Vue.set()和Vue.delete() 或者 this.$set() 和 this.$delete())
                */
            // 新增
            // this.$set(this.person,"sex","男");
            // Vue.set(this.person,"sex","男");
            // console.log(this.$set === Vue.set); //同一个方法放在两个不同地方

            // 删除
            // this.$delete(this.person,"age");
            Vue.delete(this.person, "age");
          },
        },
      });
    </script>
  </body>
</html>
